//package com.example;/**
// * @Author kzc
// * @Date 2023/4/19 18:30 （可以根据需要修改）
// * @作用
// */
//
//
//
//import com.example.VO.PayConstants;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import com.fasterxml.jackson.databind.node.ObjectNode;
//
//import com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder;
//import com.wechat.pay.contrib.apache.httpclient.auth.PrivateKeySigner;
//import com.wechat.pay.contrib.apache.httpclient.auth.Verifier;
//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Credentials;
//import com.wechat.pay.contrib.apache.httpclient.auth.WechatPay2Validator;
//import com.wechat.pay.contrib.apache.httpclient.cert.CertificatesManager;
//import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
//import org.apache.http.client.methods.CloseableHttpResponse;
//import org.apache.http.client.methods.HttpPost;
//import org.apache.http.entity.StringEntity;
//import org.apache.http.impl.client.CloseableHttpClient;
//import org.apache.http.util.EntityUtils;
//import org.junit.After;
//import org.junit.Before;
//import org.junit.jupiter.api.Test;
//
//import java.io.ByteArrayOutputStream;
//import java.io.IOException;
//import java.nio.charset.StandardCharsets;
//import java.security.PrivateKey;
//
///**
// * @作用: business
// *
// * @说明:
// *
// * @author: kzc
// *
// * @日期: 2023-04-19 18:30
// **/
//
//
//public class Mytest {
//
//    private static final String privateKey = PayConstants.privateKey; // 商户私钥
//    CertificatesManager certificatesManager;
//    private static final String merchantId = PayConstants.MCHH_ID; // 商户号
//    private static final String merchantSerialNumber = PayConstants.MCH_SERIAL_NO; // 商户证书序列号
//    private static final String apiV3Key = PayConstants.API_V3KEY; // API V3密钥
//    private Verifier verifier;
//     CloseableHttpClient httpClient;
//    @After
//    public void after() throws IOException {
//        httpClient.close();
//    }
//    @Before
//    public void setup() throws Exception {
//        PrivateKey merchantPrivateKey = PemUtil.loadPrivateKey(privateKey);
//        // 获取证书管理器实例
//        certificatesManager = CertificatesManager.getInstance();
//        // 向证书管理器增加需要自动更新平台证书的商户信息
//        certificatesManager.putMerchant(merchantId, new WechatPay2Credentials(merchantId,
//                        new PrivateKeySigner(merchantSerialNumber, merchantPrivateKey)),
//                apiV3Key.getBytes(StandardCharsets.UTF_8));
//        // 从证书管理器中获取verifier
//        verifier = certificatesManager.getVerifier(merchantId);
//        httpClient = WechatPayHttpClientBuilder.create()
//                .withMerchant(merchantId, merchantSerialNumber, merchantPrivateKey)
//                .withValidator(new WechatPay2Validator(certificatesManager.getVerifier(merchantId)))
//                .build();
//    }
////    jsapi
//    @Test
//    public  void createOrder() throws IOException {
//        HttpPost httpPost = new HttpPost("https://api.mch.weixin.qq.com/v3/pay/transactions/app");
//        httpPost.addHeader("Accept", "application/json");
//        httpPost.addHeader("Content-type","application/json; charset=utf-8");
//
//        ByteArrayOutputStream bos = new ByteArrayOutputStream();
//        ObjectMapper objectMapper = new ObjectMapper();
//        ObjectNode rootNode = objectMapper.createObjectNode();
//        rootNode.put("mchid", PayConstants.MCHH_ID)
//                .put("appid", PayConstants.APP_ID)
//                .put("description", "球拍")
//                .put("notify_url", "https://www.weixin.qq.com/wxpay/pay.php")
//                .put("out_trade_no", "1217752501201407033233368018");
//        rootNode.putObject("amount")
//                .put("total", 1);
//        rootNode.putObject("payer");
////                .put("openid", "oUpF8uMuAJO_M2pxb1Q9zNjWeS6o");
//
//        objectMapper.writeValue(bos, rootNode);
//
//        httpPost.setEntity(new StringEntity(bos.toString("UTF-8"), "UTF-8"));
//        CloseableHttpResponse response = httpClient.execute(httpPost);
//
//        String bodyAsString = EntityUtils.toString(response.getEntity());
//        System.out.println(bodyAsString);
//    }
//}
